<template>
	<div class="downloadDetails">
		<div class="dialog animated" :class="open? 'fadeIn':'fadeOut'" v-show="show" :style="{visibility: (visible?'visible':'hidden')}">
			<div class="panel animated" :class="open? 'zoomIn':''">
				<div class="title">
					{{resourceItem.name + resourceItem.fileType}}
					<div class="close" @click="cancel()"></div>
				</div>
				<div style="padding: 0.2rem 0.3rem 0.6rem 0.3rem;">
					<div class="resource_details">
						文件格式：{{resourceItem.fileType}} &emsp;&emsp;
						文件大小：{{resourceItem.fileSize}} &emsp;&emsp;
						上传时间：{{resourceItem.createTime}}</div>
					<div class="row_one">
						<el-select v-model="param.actionType" clearable placeholder="选择下载状态" style="width: 1.8rem;">
							<el-option v-for="item in statusList" :key="item.name" :label="item.name" :value="item.value"></el-option>
						</el-select>&emsp;
						<el-input style="width: 3.5rem;" clearable placeholder="搜索 校区名称" v-model="param.objectName" class="input_search"></el-input>
						<div class="search_btn" @click="search()" style="margin-left:0.1rem;">搜索</div>
					</div>
					<div style="margin-top:0.2rem">
						<table class="table" cellspacing="0">
							<thead class="thead">
								<tr>
									<td style="width: 4rem;">校区名称</td>
									<td style="width: 4rem;">下载状态</td>
									<td style="width: 4rem;">下载时间</td>
									<td style="width: 4rem;">下载人员</td>
								</tr>
							</thead>
							<tbody class="tbody">
								<tr v-for="item,index in tableList">
									<td>{{item.objectName}}</td>
									<td>{{item.actionType == null || item.actionType == 0 ? '未下载':'已下载'}}</td>
									<td>{{item.downloadTime}}</td>
									<td>{{item.userName}}</td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="campus_details">共发布{{campusObject.assignCount}}个校区，已有{{campusObject.actionCount}}个校区下载</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	var vm;
	export default {
		data: function() {
			return {
				show: false,
				open: false,
				visible: false,
				userInfo:null,
				fileSize : 0,
				param: {
					objectName: "",
					resourceId: "",
					actionType: null
				},
				statusList: [{
						value: 1,
						name: "已下载"
					},
					{
						value: 0,
						name: "未下载"
					}
				],
				campusObject:{
					assignCount:0,
					actionCount:0
				},
				resourceItem: {},
				tableList:[],
				downloadList: []
			};
		},
		methods: {
			init: function(resourceItem) {
				vm.show = true;
				setTimeout(function() {
					vm.open = true;
					vm.visible = true;
				}, 11);
				vm.resourceItem = resourceItem;
				vm.setFileSize();
				vm.param.resourceId = resourceItem.id;
				vm.apiGetList();
			},
			sure: function() {
				vm.cancel();
			},
			setFileSize : function(size) {
				var size = vm.resourceItem.size;
				//size单位是KB
				if(size > 1024*1024) {
					//大于1G,单位设成GB
					size = (size / (1024 * 1024)).toFixed(2) +"GB";
				}else if(size > 1024) {
					//大于1M,单位设成MB
					size = (size / 1024).toFixed(2) +"MB";
				}else {
					size = size + "KB";
				}
				vm.resourceItem.fileSize = size;
			},
			apiGetList(){
				let campusInfoList=[];
				vm.userInfo.campusList.forEach(ele=>{
					campusInfoList.push({
						campusId:ele.campusId,
						campusName:ele.name
					});
				});
				api.assignList({
					resourceId:vm.resourceItem.id,
					assignObjectType:vm.resourceItem.assignObjectType,
					campusInfoList:campusInfoList
				}).then(function(result) {
					let data=result.data;
					if(data.resultCode==2000){
						vm.downloadList = data.info.downloadInfoDtoList;
						vm.campusObject.assignCount = data.info.assignCount;
						vm.campusObject.actionCount = data.info.actionCount;
						vm.search()
					}
					
				});
			},
			search: function() {
				vm.tableList=[];
				let isSelectOk=function(o){
					if(vm.param.actionType===0){
						if(!o.actionType)return true;
						return false;
					}
					else if(vm.param.actionType===1){
						if(o.actionType==1)return true;
						return false;
					}
					return true;
				}
				let isInputOk=function(o){
					if(!vm.param.objectName)return true;
					if(o.objectName){
						if(o.objectName.includes(vm.param.objectName)){
							return true;
						}
					}
					return false;
				}
				for(let i=0;i<vm.downloadList.length;i++){
					let row=vm.downloadList[i];
					if(isSelectOk(row)&&isInputOk(row)){
						vm.tableList.push(row);
					}
				}

				
			},
			cancel: function() {
				//隐藏弹窗
				vm.open = false;
				vm.downloadList = [];
				vm.tableList = [];
				setTimeout(function() {
					vm.show = false;
					vm.visible = false;
				}, 500);
			}
		},
		created: function() {
			vm = this;
			vm.userInfo = tool.getItem(lsKey.user, true);
		}
	};
</script>
<style lang="scss">
	.downloadDetails {
		.el-form-item__label {
			font-size: 0.16rem;
			color: #666666;
		}
		.el-checkbox__label {
			font-size: 0.16rem;
			color: #666666;
		}
		.resource_details {
			width: 100%;
			height: 0.44rem;
			font-size: 0.16rem;
			color: #666666;
		}
		.campus_details {
			margin-top: 0.2rem;
			width: 100%;
			height: 0.34rem;
			font-size: 0.14rem;
			color: #666666;
		}
	}
</style>
<style scoped src="@/style/module/table.css"></style>
<style scoped src="@/style/module/dialog.css"></style>
<style scoped>

</style>